package com.taotao.protal.service.impl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.taotao.common.pojo.TaotaoResult;
import com.taotao.common.util.HttpClientUtil;
import com.taotao.pojo.TbUser;
import com.taotao.protal.service.UserService;

/****
 * 用户登录service
 * @author Administrator
 *
 */
@Service
public class UserServiceImpl implements UserService{
	
	//#单点登录系统url
	@Value("${SSO_BASE_URL}")
	public String SSO_BASE_URL;
	//#根据token取用户信息url
	@Value("${SSO_USER_TOKEN}")
	private String SSO_USER_TOKEN;
	//#单点登录系统登录url
	@Value("${SSO_PAGE_LOGIN}")
	public String SSO_PAGE_LOGIN;
	
	
	/***
	 * 根据token获取用户信息
	 * @param token
	 * @return
	 */
	@Override
	public TbUser getUserByToken(String token){
		try {
			//调用sso系统的服务，根据token取用户信息
			String json = HttpClientUtil.doGet(SSO_BASE_URL + SSO_USER_TOKEN + token);
			//把json转换成TaotaoREsult
			TaotaoResult result = TaotaoResult.formatToPojo(json,TbUser.class);
			if(result.getStatus() == 200){
				TbUser user = (TbUser)result.getData();
				return user;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
		
	}

	public String getSSO_BASE_URL() {
		return SSO_BASE_URL;
	}

	public void setSSO_BASE_URL(String sSO_BASE_URL) {
		SSO_BASE_URL = sSO_BASE_URL;
	}

	public String getSSO_USER_TOKEN() {
		return SSO_USER_TOKEN;
	}

	public void setSSO_USER_TOKEN(String sSO_USER_TOKEN) {
		SSO_USER_TOKEN = sSO_USER_TOKEN;
	}
	
	
	
	
	

}
